﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 第三次课堂作业
{
    class ShapeFactory
    {
        public Shape getShape(int x)
        {
            Random r = new Random();
            Shape shapeModel;
            switch(x)
            {
                case 1:
                    shapeModel = new Rectangle(r.Next(20) - 10, r.Next(20) - 10);
                    if (shapeModel.isLegal())
                        return shapeModel;
                    break;
                case 2:
                    shapeModel = new Square(r.Next(20) - 10);
                    if (shapeModel.isLegal())
                        return shapeModel;
                    break;
                case 3:
                    shapeModel = new Triangle(r.Next(20) - 10, r.Next(20) - 10, r.Next(20) - 10);
                    if (shapeModel.isLegal())
                        return shapeModel;
                    break;
            }
            return null;
        }
    }
}
